package yxt.net.websocket.example.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;
import yxt.net.websocket.example.handler.TestHandler;

import javax.annotation.Resource;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author zhangxiaolin
 * @since 2022/1/25$ 13:32$
 */
@EnableWebSocket
@Configuration
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private TestHandler testHandler;
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(testHandler, "/textHandler").setAllowedOrigins("*").addInterceptors(new HttpSessionHandshakeInterceptor());//.withSockJS();

    }
}
